from rest_framework import serializers
from . import models

class GoodsSerializer(serializers.ModelSerializer):
    class Meta:
        model=models.Goods
        fields="__all__"


# 订单序列化
class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model=models.Order
        fields="__all__"


class OrderSerializer1(serializers.ModelSerializer):
    goods=serializers.SerializerMethodField()
    class Meta:
        model=models.Order
        fields=('goods',)

    def get_goods(self,obj):
        data=GoodsSerializer(obj.goods)
        return data.data